jQuery(function() {
	jQuery('#recordDate').val(moment(jQuery('#recordDate1').val()).format("YYYY-MM-DD"));
	jQuery('#customer').val(jQuery('#customer1').val());
	//////////////////////////信息///////////////////////////////////////////////
	//保存
	var saveExperience=function(state){
		var recordDate = jQuery('#recordDate').val();
		var customer = jQuery('#customer').val();
		var deviceType = jQuery('#deviceType').val();
		var trouble=jQuery('#trouble').val();
		var reason=jQuery('#reason').val();
		var result=jQuery('#result').val();
		var memo=jQuery('#memo').val();
		var id=jQuery('#Id').val();
		var url = window.rootPath + "/ui/aftersaleexperience/save";
		// 判断是编辑还是新增
		if (id == "") {
			var d = {
				"recordDate": recordDate,
				// "createTime":createTime,
				"customer":customer,
				"deviceType": deviceType,
				"trouble": trouble,
				"reason": reason,
				"result": result,
				"memo": memo,


			};
		} else {
			var d = {
				"id" : id,
				"recordDate": recordDate,
				// "createTime":createTime,
				"customer":customer,
				"deviceType": deviceType,
				"trouble": trouble,
				"reason": reason,
				"result": result,
				"memo": memo,
    
			};

		}
		jQuery(".btn").attr("disabled", true);
		jQuery.ajax({
			type: 'post',
			url:  encodeURI(url),
			data: JSON.stringify(d),
			dataType: 'json',
			contentType: 'application/json;charset=utf-8',
			success: function (data) {
				jQuery(".btn").attr("disabled", false);
				if(state=='saveBtn'){
					window.location = window.rootPath+"/ui/aftersaleexperience";}
					else if(state='upload'){
					var experienceId = data.afterSaleExperience.id;
					jQuery('#Id').val(experienceId); 
					fileUpload(experienceId, "典型案例附件",null,'attachmentnumber');		
					}           
			}
		});
	}
	// 保存客户信息
	jQuery('.saveBtn').on('click', function() {
		if (jQuery("#ExperienceAdd") && !jQuery("#ExperienceAdd").Validform({
				tiptype : 3,
				showAllError : true
			}).check(false)) {
			return;
		};
		saveExperience('saveBtn');
	});

// 上传附件
	jQuery(".upload").on('click', function() {
		var experienceId = jQuery("#Id").val();
		if (experienceId == "") {
			if (jQuery("#ExperienceAdd") && !jQuery("#ExperienceAdd").Validform({
					tiptype : 3,
					showAllError : true
				}).check(false)) {
				return;
			}
			;
			saveExperience('upload');
//			$.springLemonDialog({
//				content : '将保存典型案例附件，是否继续',// 确认文本
//				clickButton : function(sender, modal, index) {// 按钮事件处理
//					if (index == 0) {
//						saveExperience('upload');
//					}
//					$(this).closeDialog(modal);
//				}
//			});
		
		} else {
			fileUpload(experienceId, "典型案例附件",null,'attachmentnumber');
	
		}
	});
// 下载附件
	jQuery(".download").on('click', function() {
		var experienceId = jQuery("#Id").val();
		filedown(experienceId, '典型案例附件','1');
	});
    ////获附件数量
	var experienceId = jQuery("#Id").val();
	var numId='attachmentnumber';
	if(experienceId !=''){
		showANum(experienceId,'典型案例附件',numId);
	}
	
});